//https://www.yuque.com/huantaipingyang-jucwl/ipzeev/eefscuipsf3kp2og#Rzat1
//https://leetcode.cn/problems/number-of-subsequences-that-satisfy-the-given-sum-condition/

//左老师的和leetcode的暴力递归解法 区别就是 是不是连续子数组；
//暴力解法
class Solution {
public:
    bool check(vector<int>& num,int l,int r,int target){

        int min = INT_MAX;
        int max = INT_MIN;
        for(int i=l;i<=r;++i){
            if(num[i] > max){
                max=num[i];
            }
            if(num[i] < min){
                min=num[i];
            }
        }    
        bool res=false;
        if((max+min)<=target) {
            res=true;
        }    
        return res;
    }
    int numSubseq(vector<int>& nums, int target) {
        int res=0;
        if(nums.empty()) return res;
        
        for(int i=nums.size()-1;i>=0;--i){
            for(int j=0;j<=i;++j){
                if(check(nums,j,i,target)){
                    ++res;
                }
            }
        }
        return res;

    }
};
